﻿//cesium 三维的影响结构数据 -->
// 人居环境

var chartrjhj = (function () {
    // 初始化
    function chartrjhj() {
        // 属性

    };

    ////
    chartrjhj.prototype.init = function (options) {
        this.loadtqyb();
        this.loadhxztt();
        this.loadrlt();
    }
    /*
    天气预报
    */
    chartrjhj.prototype.loadtqyb = function (options) {
        var tmpl = htmldoc(function () {/*
           <div class="blk_fc_c0_i">          
            <p class="wt_fc_c0_i_day ">10-09 星期一</p>
            <p class="wt_fc_c0_i_icons clearfix">
                <img class="icons0_wt png24" src="http://www.sinaimg.cn/dy/weather/main/index14/007/icons_42_yl/w_02_08_00.png" alt="多云" title="多云">
                <img class="icons0_wt png24" src="http://www.sinaimg.cn/dy/weather/main/index14/007/icons_42_yl/w_02_08_01.png" alt="多云" title="多云">
            </p>
            <p class="wt_fc_c0_i_times"> <span class="wt_fc_c0_i_time">白天</span>  <span class="wt_fc_c0_i_time">夜间</span>

            </p>
            <p class="wt_fc_c0_i_temp">29°C / 24°C</p>
            <p class="wt_fc_c0_i_tip">东南风 3～4级</p>
            <div class="wt_fc_c0_i_level level_bg1">
                <div class="l">48</div>
                <div class="r">优</div>
                <!-- 48 -->
            </div>
        </div>
        */});
        // 基于准备好的dom，初始化echarts实例
        $("#vpc18ccmychartbox1").html(tmpl);

    }

    /*
      * 人居环境
      */
    chartrjhj.prototype.loadhxztt = function (options) {

        //时间
        var times = [];
        var datas = [];
        //数据
        var tmps = [];

        for (var i = 0; i < 12; i++) {
            times.push(i + "点");
            datas.push(i * 25);
            tmps.push(350);
        }

        var option = {

            backgroundColor: 'rgba(0,0,0,0)',
            legend: {
                show: "false",
                bottom: 20,
                textStyle: {
                    color: '#fff',
                },
                data: ['钥匙量', '有效房源量']
            },

            grid: {
                left: '3%',
                right: '4%',
                bottom: '10%',
                containLabel: true
            },

            tooltip: {
                show: "true",
                trigger: 'axis',
                axisPointer: {
                    // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            yAxis: {
                type: 'value',
                axisTick: {
                    show: false
                },
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: '#2B80CF',
                    }
                },
                splitLine: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
            },
            xAxis: [
                {
                    type: 'category',
                    axisTick: {
                        show: false
                    },
                    axisLine: {
                        show: false,
                        lineStyle: {
                            color: '#2B80CF',
                        }
                    },

                    data: times
                },
                {
                    type: 'category',
                    axisLine: { show: false },
                    axisTick: { show: false },
                    axisLabel: { show: false },
                    splitArea: { show: false },
                    splitLine: { show: false },
                    data: times
                },

            ],
            visualMap: {
                show: "false",
                top: -110,
                right: -110,
                pieces: [{
                    gt: 0,
                    lte: 50,
                    color: '#096'
                }, {
                        gt: 50,
                        lte: 100,
                        color: '#ffde33'
                    }, {
                        gt: 100,
                        lte: 150,
                        color: '#ff9933'
                    }, {
                        gt: 150,
                        lte: 200,
                        color: '#cc0033'
                    }, {
                        gt: 200,
                        lte: 300,
                        color: '#660099'
                    }, {
                        gt: 300,
                        color: '#277ace'
                    }],
                outOfRange: {
                    color: '#999'
                }
            },
            series: [
                {
                    name: '爆表值',
                    type: 'bar',
                    xAxisIndex: 1,
                    visualMap: "false",
                    itemStyle: {
                        normal: {
                            show: true,
                            color: '#277ace',
                            barBorderRadius: 50,
                            borderWidth: 0,
                            borderColor: '#333',
                        }
                    },
                    barGap: '0%',
                    barCategoryGap: '50%',
                    data: tmps
                },

                {
                    name: 'AQI',
                    type: 'bar',
                    itemStyle: {
                        normal: {
                            show: true,
                            color: '#5de3e1',
                            barBorderRadius: 50,
                            borderWidth: 0,
                            borderColor: '#333',
                        }
                    },
                    label: {
                        normal: {
                            show: true,
                            position: 'top',
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    },
                    barGap: '0%',
                    barCategoryGap: '50%',
                    data: datas
                }
            ]
        };

        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('vpc18ccmychartbox2'));
        myChart.setOption(option);

        var myChart1 = echarts.init(document.getElementById('vpc17ccmychartbox1'));
        myChart1.setOption(option);
    }
    /*
    月度AQI
    */
    chartrjhj.prototype.loadrlt = function (options) {
        function getVirtulData(year) {
            year = year || '2017';
            var date = +echarts.number.parseDate(year + '-09-01');
            var end = +echarts.number.parseDate((+year + 1) + '-09-30');
            var dayTime = 3600 * 24 * 1000;
            var data = [];
            for (var time = date; time < end; time += dayTime) {
                data.push([
                    echarts.format.formatTime('yyyy-MM-dd', time),
                    Math.floor(Math.random() * 1000)
                ]);
            }
            return data;
        }
         
        var option = {
            tooltip: {
                position: 'top',
                formatter: function (p) {
                    var format = echarts.format.formatTime('yyyy-MM-dd', p.data[0]);
                    return format + ': ' + p.data[1];
                }
            },

            calendar: [

                {
                    top: 'middle',
                    left: 'center',
                    orient: 'vertical',
                    cellSize: 35,
                    yearLabel: {
                        show: false,
                        margin: 50,
                        textStyle: {
                            fontSize: 30
                        }
                    },
                    dayLabel: {
                        show: false,
                        firstDay: 1,
                        nameMap: 'cn'
                    },
                    monthLabel: {
                        show: false,
                        nameMap: 'cn',
                        margin: 15,
                        textStyle: {
                            fontSize: 20,
                            color: '#999'
                        }
                    },
                    range: '2015-09',

                }],

            series: [{
                type: 'heatmap',
                coordinateSystem: 'calendar',
                calendarIndex: 0,
                data: getVirtulData(2015),
                label: {
                    normal: {
                        show: true,
                        formatter: function (params) {
                            //
                            var datas = params.value[0].split("-");
                            return datas[2];
                            //return '\n\n\n' + (params.value[3] || '');
                        },
                    }
                },
                itemStyle: {
                    normal: {
                        color: function (params) {
                            var data = params.value[1];
                            if (data < 50) {
                                return 'rgba(0, 255, 0, 0.5)';
                            } else if (data > 50 && data < 100) {
                                return 'rgba(255, 255, 0, 0.5)';
                            }
                            else {
                                return 'rgba(0, 0, 0, 0.5)';
                            }
                        },
                        shadowBlur: 10,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }]
        };
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('vpc18ccmychartbox3'));
        myChart.setOption(option);

        var myChart2 = echarts.init(document.getElementById('vpc15ccmychartbox1'));
        myChart2.setOption(option); 
    }

    // 返回
    return chartrjhj;
})();